import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";

export const childrenRoutes: Array<RouteRecordRaw> = [
  {
    path: "/home",
    name: "home",
    component: () =>
      import(/* webpackChunkName: "home" */ "@/views/home/homeView.vue"),
    meta: {
      title: "首页",
    },
  },
  {
    path: "/forum",
    name: "forum",
    component: () =>
      import(/* webpackChunkName: "forum" */ "@/views/forum/forumView.vue"),
    meta: {
      title: "论坛",
    },
  },
  {
    path: "/select/car",
    name: "selectCar",
    component: () =>
      import(
        /* webpackChunkName: "selectCar" */ "@/views/selectCar/selectCarView.vue"
      ),
    meta: {
      title: "选车",
    },
  },
  {
    path: "/old/car",
    name: "oldCar",
    component: () =>
      import(/* webpackChunkName: "oldCar" */ "@/views/oldCar/oldCarView.vue"),
    meta: {
      title: "二手车",
    },
  },
  {
    path: "/my",
    name: "my",
    component: () =>
      import(/* webpackChunkName: "my" */ "@/views/my/myView.vue"),
    meta: {
      title: "我的",
    },
  },
];

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "layout",
    redirect: "/select/car",
    component: () =>
      import(/* webpackChunkName: "layout" */ "@/views/layout/layoutView.vue"),
    children: childrenRoutes,
  },
  {
    path: "/search",
    name: "search",
    component: () =>
      import(/* webpackChunkName: "search" */ "@/views/search/searchView.vue"),
  },
  {
    path: "/detail/:id",
    name: "detail",
    // 将动态路由参数传递给组件的props
    props: true,
    component: () =>
      import(/* webpackChunkName: "detail" */ "@/views/detail/detailView.vue"),
  },
  {
    path: "/login",
    name: "login",
    component: () =>
      import(/* webpackChunkName: "login" */ "@/views/login/loginView.vue"),
  },
  {
    path: "/history/record",
    name: "historyRecord",
    component: () =>
      import(/* webpackChunkName: "historyRecord" */ "@/views/historyRecord/historyRecordView.vue"),
  },
  {
    path: '/:pathMatch(.*)*',
    name: "notFound",
    component: () =>
      import(/* webpackChunkName: "notFound" */ "@/views/notFound/notFoundView.vue"),
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

export default router;
